const formContainer = {
  type: 'form',
  rules: {
    bussType: [
      {
        required: true,
        message: '业务类型不能为空'
      }
    ],
    projectName: [
      {
        required: true,
        message: '请输入项目名称'
      }
    ],
    channelCode: [
      {
        required: true,
        message: '请输入渠道码'
      }
    ],
    supplier: [
      {
        required: true,
        message: '请输入合作方名称'
      }
    ],
    status: [
      {
        required: true,
        message: '请选择是否启用'
      }
    ]
  },
  columnCount: 2,
  body: [
    {
      type: 'select',
      prop: 'bussType',
      label: '业务类型',
      placeholder: '请选择业务类型',
      fieldNames: { label: 'dictLabel', value: 'dictValue' },
      api: '/system/dict/data/type/t_buss_type'
    },
    {
      type: 'input-text',
      prop: 'projectName',
      label: '项目名称',
      placeholder: '请输入项目名称'
    },
    {
      type: 'input-text',
      prop: 'channelCode',
      label: '渠道码',
      placeholder: '请输入渠道码'
    },
    {
      type: 'input-text',
      prop: 'supplier',
      label: '合作方名称',
      placeholder: '请输入合作方名称'
    },
    {
      type: 'select',
      prop: 'status',
      label: '是否启用',
      placeholder: '请选择是否启用',
      fieldNames: { label: 'dictLabel', value: 'dictValue' },
      api: {
        url: '/system/dict/data/type/sys_normal_disable',
        responseAdaptor: (response) => {
          const data = response.data
          const map = {}
          data.forEach((item) => {
            map[item.dictValue] = item.dictLabel
          })
          return {
            data: map
          }
        }
      }
    }
  ]
}

const columns = [
  {
    field: 'id',
    title: 'id',
    width: 180
  },
  {
    field: 'bussType',
    title: '业务类型',
    comType: 'lowCode',
    body: {
      type: 'mapping',
      value: '${bussType}',
      cache: true,
      api: {
        url: '/system/dict/data/type/t_buss_type',
        responseAdaptor: function (response){
          const data = response.data
          const map = {}
          data.forEach((item) => {
            map[item.dictValue] = item.dictLabel
          })
          return {
            data: map
          }
        }
      }
    }
  },
  {
    field: 'projectName',
    title: '项目名称'
  },
  {
    field: 'supplier',
    title: '合作方名称'
  },
  {
    field: 'channelCode',
    title: '渠道码'
  },
  {
    field: 'status',
    title: '是否启用',
    comType: 'lowCode',
    body: {
      type: 'mapping',
      value: '${status}',
      cache: true,
      api: {
        url: '/system/dict/data/type/sys_normal_disable',
        responseAdaptor: (response) => {
          console.log('response', response)
          const data = response.data
          const map = {}
          data.forEach((item) => {
            map[item.dictValue] = item.dictLabel
          })
          return {
            data: map
          }
        }
      }
    }
  },
  {
    field: 'operation',
    title: '操作',
    comType: 'lowCode',
    body: {
      type: 'space',
      body: [
        {
          type: 'link',
          actionType: 'dialog',
          reflectAttr: { type: 'primary' },
          body: '修改',
          dialog: {
            title: '修改',
            body: {
              ...formContainer,
              data: {
                bussType: '${bussType}',
                projectName: '${projectName}',
                channelCode: '${channelCode}',
                supplier: '${supplier}',
                status: '${status}'
              },
              api: {
                url: '/supplier/info/updateSupplierInfo',
                method: 'post',
                successMsg: '修改成功',
                data: {
                  bussType: '${bussType}',
                  projectName: '${projectName}',
                  channelCode: '${channelCode}',
                  supplier: '${supplier}',
                  status: '${status}',
                  id: '${id}'
                }
              }
            }
          }
        },
        {
          type: 'link',
          actionType: 'confirm',
          reflectAttr: { type: 'danger' },
          messageContent: '确定要删除吗？',
          body: '删除',
          api: '/menu/config/deleteMenuConfigById/${id}'
        }
      ]
    }
  }
]

const querys = [
  {
    prop: 'bussType',
    label: '业务类型',
    type: 'select',
    placeholder: '请选择业务类型',
    fieldNames: { label: 'dictLabel', value: 'dictValue' },
    api: '/system/dict/data/type/t_buss_type'
  },
  {
    prop: 'projectName',
    label: '项目名称',
    placeholder: '请输入项目名称',
    type: 'input-text'
  },
  {
    prop: 'supplier',
    label: '合作方名称',
    placeholder: '请输入合作方名称',
    type: 'input-text'
  },
  {
    prop: 'channelCode',
    label: '渠道码',
    placeholder: '请输入渠道码',
    type: 'input-text'
  }
]

export default {
  type: 'page',
  body: {
    type: 'crud',
    columns,
    querys,
    api: {
      url: '/supplier/info/selectSupplierInfoList',
      responseData: ''
    },
    tableTop: {
      type: 'el-row',
      reflectAttr: {
        type: 'flex',
        justify: 'end',
        align: 'center'
      },
      body: {
        type: 'button',
        body: '新增',
        actionType: 'dialog',
        reflectAttr: { type: 'primary' },
        dialog: {
          title: '新增',
          body: {
            ...formContainer,
            api: {
              url: '/supplier/info/insertSupplierInfo',
              method: 'post',
              data: {
                bussType: '${bussType}',
                projectName: '${projectName}',
                channelCode: '${channelCode}',
                supplier: '${supplier}',
                status: '${status}'
              }
            }
          }
        }
      }
    }
  }
}
